package study.domain.blog;

import java.io.Serializable;

import lombok.Data;

@Data
public class InboxData implements Serializable, Comparable<InboxData> {

	private static final long serialVersionUID = 6384289617684368622L;

	private Long id;

	private Long userId;

	public InboxData() {
	}

	public InboxData(Long userId) {
		this.userId = userId;
	}

	public InboxData(Long id, Long userId) {
		this.id = id;
		this.userId = userId;
	}

	public InboxData(Post post) {
		this.id = post.getId();
		this.userId = post.getUser().getUserId();
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		result = prime * result + ((userId == null) ? 0 : userId.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;

		InboxData other = (InboxData) obj;
		if (userId != null && other.userId != null && id != null && other.id != null) {
			if (!userId.equals(other.userId)) {
				return false;
			}
			if (!id.equals(other.id)) {
				return false;
			}
			return true;
		} else if (userId != null && other.userId != null && id == null && other.id != null) {
			if (userId.equals(other.userId)) {
				return true;
			}
			return false;
		}
		return false;
	}

	@Override
	public int compareTo(InboxData o) {
		if (id != null && o != null && o.getId() != null) {
			return id.compareTo(o.getId());
		}
		return 0;
	}

}
